package com.luculent.util.extension.datamasking.util;

import com.google.common.io.BaseEncoding;

/**
 * string/url -> hex/base64 编解码工具集(via guava BaseEncoding)
 * @author zhangyang
 * @date 2020/11/4 11:03
 */
public class EncodeUtil {
    /**
     * Hex编码, 将byte[]编码为String，默认为ABCDEF为大写字母.
     */
    public static String encodeHex(byte[] input) {
        return BaseEncoding.base16().encode(input);
    }

    /**
     * Hex解码, 将String解码为byte[].
     *
     * 字符串有异常时抛出IllegalArgumentException.
     */
    public static byte[] decodeHex(CharSequence input) {
        return BaseEncoding.base16().decode(input);
    }
}
